const http = require('http');
const fs = require('fs');
http.createServer((request, response) => {
    response.setHeader('Access-Control-Allow-Origin', '*');
    let body = [];
    request.on('data', (chunk) => {
        body.push(chunk)
    })
    request.on('end', () => {
        body = Buffer.concat(body);
        body = body.toString('ascii');
        body = body.split(/png\r?\n\r?\n/)[1];
        body = body.split(/\r?\n------WebKitFormBoundary/)[0];
        body = new Buffer(body);
        console.log(body.length)
        fs.writeFile('lll.png', body, function(err) {
            if (err) throw err;
            console.log('File saved.')
        })
        response.write('我收到咯');
        response.end();
    })
}).listen(8081)